﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace GreetingCreator
{
    public class GraphicElementListBox : ListBox
    {
        public GraphicElementListBox()
            : base()
        { }

        protected override void PrepareContainerForItemOverride(DependencyObject element, object item)
        {
            base.PrepareContainerForItemOverride(element, item);

            GreetingServiceReference.GraphicElementData graphicElement = item as GreetingServiceReference.GraphicElementData;
            ListBoxItem listBoxItem = element as ListBoxItem;

            if (graphicElement != null && listBoxItem != null)
            {
                DataTemplate dt = Application.Current.Resources[graphicElement.TemplateName] as DataTemplate;
                listBoxItem.ContentTemplate = dt;
            }            
        }
    }
}
